﻿using Legend.Component.Interface;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System;

namespace Legend.Component.Common
{
    public class SignwaveMovement : Movement
    {
        private float speed = 200;
        private float multifier = 200;
        private float frequency = 3000;
        private double firstUpdateTime = 0;

        public float Speed
        {
            get { return speed; }
            set { speed = value; }
        }

        public float Multifier
        {
            get { return multifier; }
            set { multifier = value; }
        }

        public float Frequency
        {
            get { return frequency; }
            set { frequency = value; }
        }
        
        public override void Update(GameTime gameTime, ContentManager contentManager)
        {
            double elapsed = 0;

            if (firstUpdateTime == 0)
            {
                firstUpdateTime = gameTime.TotalGameTime.TotalMilliseconds;
            }
            else
            {
                elapsed = gameTime.TotalGameTime.TotalMilliseconds - firstUpdateTime;
            }
            
            Vector3 position = Position;

            position.X = (float)Math.Sin((float)(elapsed / frequency * 2 * Math.PI)) * Multifier;
            position.Y += speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000;

            Position = position;
        }
    }
}
